package servlet;

import domain.CallNumber;
import domain.User;
import test.test;
import service.CallNumberService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UserServlet")
public class UserServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.v->c:从页面读取参数，利用req对象


        User user = new User();

        String telephone = req.getParameter("telephone");
        int year = Integer.parseInt(req.getParameter("year"));
        int month = Integer.parseInt(req.getParameter("month"));

        user.setTelephone(telephone);
        user.setYear(year);
        user.setMonth(month);




        req.getSession().setAttribute("user",user);


        System.out.println("Userservlet is ok");

        resp.setContentType("application/json;charset=utf-8");

        resp.sendRedirect("index.html");


    }
}
